 <?php
 include 'ajax_init.php';
 
 if ($_GET[module]=='home'){
 ?>
			<!-- CONTENT -->
		  <div id="content">            
          <!-- Slideshow Headline Berita -->
          <div id="content-kiri">
            <div id="divTrigger">
              <a href="javascript:;" onClick="bukaContent(this,'div1')" id="slideAwal">1</a>
              <a href="javascript:;" onClick="bukaContent(this,'div2')">2</a>
              <a href="javascript:;" onClick="bukaContent(this,'div3')">3</a>
              <a href="javascript:;" onClick="bukaContent(this,'div4')">4</a>
              <a href="javascript:;" onClick="bukaContent(this,'div5')">5</a>
            </div><br />

            <div id="divContent"> 
              <?php
                $terkini=mysql_query("SELECT * FROM berita 
                                      WHERE headline='Y' ORDER BY id_berita DESC LIMIT 5");
                $no=1;
              	while($t=mysql_fetch_array($terkini)){
                  echo "<div id='div$no'>
                          <img src=foto_berita/small_$t[gambar] width='350' height='250' />
                          <span class='t'><a href='berita-$t[id_berita]-$t[judul_seo].html'>$t[judul]</a></span>
                        </div>";           
                  $no++;
                } 
              ?>
            </div>          
          </div><!-- / end content-kiri untuk headline berita -->

          <!-- TAB -->         
          <div id="content-kanan">
            <div id="tabsview">
		          <div id="tab1" class="tab_sel" onClick="javascript: displayPanel('1');" align="center">&nbsp; Most Like &nbsp;</div>
 		          <div id="tab2" class="tab" style="margin-left: 1px;" onClick="javascript: displayPanel('2');" align="center">&nbsp; Most Comment &nbsp;</div>
 		          <div id="tab3" class="tab" style="margin-left: 1px;" onClick="javascript: displayPanel('3');" align="center">&nbsp; Komentar &nbsp;</div>
            </div>
  
	          <div class="tab_bdr"></div>
	          
	          <!-- tab 1: berita terpopuler -->
            <div class="panel" id="panel1" style="display: block;">
              <span>
              <ul>            
                <?php
                  $populer=mysql_query("SELECT COUNT(likes.id_berita) AS jml, berita.*,tag.nama_tag FROM likes, berita, tag WHERE likes.id_berita=berita.id_berita AND tag.id_tag=berita.id_tag GROUP BY likes.id_berita ORDER BY jml DESC LIMIT 3");
                  while($p=mysql_fetch_array($populer)){
                    echo "<li class='garisbawah'><a href=berita-$p[id_berita]-$p[judul_seo].html>$p[judul]</a> ($p[jml])</li>";
				  }
                ?>          
              </ul>
              </span>
            </div>

	          <!-- tab 2: berita terkini/terbaru -->
            <div class="panel" id="panel2" style="display: none;">
              <span>
              <ul>            
                <?php
				//SELECT COUNT(id_komentar) as jml FROM komentar GROUP BY id_berita ORDER BY komentar.id_komentar DESC LIMIT 3
                  $terkini=mysql_query("SELECT *, COUNT(komentar.id_komentar) as jml FROM komentar, berita WHERE komentar.id_berita = berita.id_berita GROUP BY komentar.id_berita ORDER BY berita.id_berita DESC LIMIT 3");
                  while($t=mysql_fetch_array($terkini)){
                    echo "<li class='garisbawah'><a href=berita-$t[id_berita]-$t[judul_seo].html>$t[judul]</a> ($t[jml])</li>";
                  }
                ?>                    
              </ul>
              </span>
            </div>
  
	          <!-- tab 3: komentar terakhir -->
            <div class="panel" id="panel3" style="display: none;">
              <span>
              <ul>        
                <?php
                  $komentar=mysql_query("SELECT * FROM berita,komentar 
                                         WHERE komentar.id_berita=berita.id_berita  
                                         ORDER BY id_komentar DESC LIMIT 7");
                  while($k=mysql_fetch_array($komentar)){
                    echo "<li class='garisbawah'><a href='http://$k[url]' target='_blank'><b>$k[nama_komentar]</b></a> 
                          pada <a href='berita-$k[id_berita]-$k[judul_seo].html#$k[id_komentar]'>$k[judul]</a></li>";
                  }
                ?>      
              </ul>
              </span>
            </div><br />  
          </div><!-- / end content-kanan untuk tabs-->

          <div id="content-kiri">
            <?php
              // Berita Sebelumnya (tampilkan 10 berita sebelumnya) 
              echo "<br /><img src=images/berita_sebelumnya.jpg><br />
                    <ul>";
              $sebelum=mysql_query("SELECT * FROM berita ORDER BY id_berita DESC LIMIT 8,10");		 
	            while($s=mysql_fetch_array($sebelum)){
	               echo "<li><b><a href='berita-$s[id_berita]-$s[judul_seo].html'>$s[judul]</a></b></li>";
	            }    
	            echo "</ul><br />";
	  
	            // Galeri Foto (tampilkan 6 foto secara horizontal)
              echo "<img src='images/galeri.jpg' /><br />";

              // Tentukan kolom
              $col = 3;
              $g = mysql_query("SELECT * FROM gallery ORDER BY id_gallery DESC LIMIT 6");
              
              echo "<table><tr>";              
              $cnt = 0;
              while ($w = mysql_fetch_array($g)) {
                if ($cnt >= $col) {
                echo "</tr><tr>";
                $cnt = 0;
                }
                $cnt++;
                echo "<td align=center valign=top><br />
                      <a id='galeri' href='img_galeri/$w[gbr_gallery]' title='$w[keterangan]'>
                      <img alt='galeri' src='img_galeri/kecil_$w[gbr_gallery]' /></a><br />
                      <a href=#><b>$w[jdl_gallery]</b></a></td>";
              }
              echo "</tr></table>";
            ?>
          </div><!-- / end content-kiri untuk berita sebelumnya dan galeri foto -->
          
          <div id="content-kanan">
            <div id="kotakjudul">
              <span class="judulhead">Kategori Berita</span>
            </div>
            <div id="kotakisi">
              <table cellpedding="2" width="100%" border="0" cellspacing="4">
              <tbody>  
                <?php
                  $kategori=mysql_query("SELECT nama_kategori, kategori.id_kategori, kategori_seo,  
                                         COUNT(berita.id_kategori) AS jml 
                                         FROM kategori LEFT JOIN berita 
                                         ON berita.id_kategori=kategori.id_kategori 
                                         WHERE kategori.aktif='Y'  
                                         GROUP BY nama_kategori");
                  while($k=mysql_fetch_array($kategori)){
                    $nama_kategori=strtoupper($k[nama_kategori]);
                    echo "<tr><td class='garisbawah'><a href=kategori-$k[id_kategori].html> $nama_kategori</a> ($k[jml])</td></tr>";
                  }
                ?>
              </tbody>
              </table>
            </div><br /> <!-- / end kategori berita -->
            
              <div id="kotakjudul">
                <span class="judulhead">Download</span>
              </div>
              <div id="kotakisi">
                <table cellpedding="2" width="100%" border="0" cellspacing="4">
                <tbody>
                  <?php
                    $download=mysql_query("SELECT * FROM download ORDER BY id_download DESC LIMIT 5");
                    while($d=mysql_fetch_array($download)){
                      echo "<tr><td>&bull; <a href='downlot.php?file=$d[nama_file]'>$d[judul]</a> ($d[hits])</td></tr>";
                    }
                  ?>
                </tbody>
                </table>
              </div><br />  <!-- / end download -->
              
          </div><!-- / end content-kanan untuk kategori berita, download, dan agenda -->
	    </div> <!-- / end content -->


<?php 
}
elseif ($_GET[module]=='detailberita'){
	echo "<div id='content'>          
           <div id='content-detail'>";            

	$detail=mysql_query("SELECT * FROM berita,users,tag
                      WHERE users.username=berita.username 
					  AND berita.id_tag = tag.id_tag
                      AND id_berita='$_GET[id]'");
	$d   = mysql_fetch_array($detail);
	$baca = $d[dibaca]+1;
	echo "<span class=judul>$d[judul]</span><br />";
	echo "<span class=posting>Diposting oleh : <b>$d[nama_lengkap]</b><br />
        Kategori: <a href=kategori-$d[id_kategori].html><b>$d[nama_kategori]</b></a><br>
		Tag : <b>$d[tag_seo]</b><br>
        Dibaca: <b>$baca</b> kali</span><br />";
	$a = datediff($waktu, $d[waktu]);
		if ($waktu)
		{ echo 'Selisih Waktu : '.$a[years].'
		tahun, '.$a[months].'
		bulan, '.$a[days].'
		hari, '.$a[hours].'
		jam, '.$a[minutes].'
		menit, '.$a[seconds].'
		detik';
		}
		echo "<br>";
			
  AddLikeDislike($_GET[id]);

  	// Apabila ada gambar dalam berita, tampilkan   
 	if ($d[gambar]!=''){
		echo "<p><span class=image><img src='foto_berita/$d[gambar]' border=0></span></p>";
	}
	// Apabila ada video dalam berita, tampilkan   
 	if ($d[video]!=''){
		echo "<p><span class=image><img src='foto_berita/$d[video]' border=0></span></p>";
	}
	
 	//$isi_berita=nl2br($d[isi_berita]); // membuat paragraf pada isi berita
	echo "$d[isi_berita] <br />";	 		  
  
  // Tampilkan judul berita yang terkait (maks: 5) 
  echo "<img src=images/berita_terkait.jpg><br /><ul>";
  // pisahkan kata per kalimat lalu hitung jumlah kata
  $pisah_kata  = $d[id_tag];

  $jml_kata = $jml_katakan-1; 
  $ambil_id = substr($_GET[id],0,4);

  // Looping query sebanyak jml_kata
  $cari = "SELECT * FROM berita WHERE (id_berita<'$ambil_id') and (id_berita!='$ambil_id') and (id_tag=$d[id_tag]) ORDER BY id_berita DESC LIMIT 5";
  $hasil  = mysql_query($cari);
  while($h=mysql_fetch_array($hasil)){
  		echo "<li><a href=berita-$h[id_berita]-$h[judul_seo].html>$h[judul]</a></li>";
  }
	echo "</ul>";

  // Apabila detail berita dilihat, maka tambahkan berapa kali dibacanya
  mysql_query("UPDATE berita SET dibaca=$d[dibaca]+1 WHERE id_berita='$_GET[id]'"); 


  // Hitung jumlah komentar
  AddCommentCount();

  // Komentar berita
  	$sql = mysql_query("SELECT * FROM komentar WHERE id_berita='$_GET[id]' AND aktif='Y' ORDER BY waktu DESC");
	$jml = mysql_num_rows($sql);
  // Apabila sudah ada komentar, tampilkan 
  if ($jml > 0){
    while ($s = mysql_fetch_array($sql)) {
      
      echo '<span id="comment' . $s[id_komentar] . '">';
      
      echo "<span class=komentar>Komentator : $s[nama_komentar]</span><br />";  
      $user = mysql_query("SELECT * FROM users,komentar WHERE users.username = komentar.komentator");
      $d = mysql_fetch_array($user);
      echo "<img src = ImgAvatar/$d[avatar] width=50 height=50><br>";
      
      $a = datediff($waktu, $s[waktu]);
      if ($waktu)
      { echo 'Selisih Waktu : '.$a[years].'
      tahun, '.$a[months].'
      bulan, '.$a[days].'
      hari, '.$a[hours].'
      jam, '.$a[minutes].'
      menit, '.$a[seconds].'
      detik';
      }
      echo "<br>";
        $isian=nl2br($s[isi_komentar]); // membuat paragraf pada isi komentar
        
          echo "$isian<br>";
      if($s[komentator]== $_SESSION[username]){
            ?>
            <form action="" method="post">
                <input name="id_berita" id="id_berita" type="hidden" value="<?php echo "$_GET[id]" ?>">
                  <input name="id_komentar" id="id_komentar" type="hidden" value="<?php echo "$s[id_komentar]" ?>">
              </td></tr><br>
              <tr><td colspan=2>
                  <input type=button name=Button value=Delete onclick="DeleteCommentClicked(<?php
                  echo $s[id_komentar] . ", " . $_GET[id]; ?>)">
                  <!--<meta http-equiv='refresh' content='0; url=media.php?module=detailberita&id=$_GET[id]'> -->
              </td></tr>
              </form>
              <?php
        //echo "<a href='media.php?module=hapuskomentar&id=$s[id_komentar]&id_berita=$_GET[id]'><b>Hapus komentar</b></a><br>";
      }
          echo "<hr color=#CCC noshade=noshade />";	 		  
      
      echo '</span>';
    }
  }
	include "komentar.php";
  echo "</div>
    </div>";            
}

// Modul hasil pencarian berita 
elseif ($_GET[module]=='hasilcari'){
	echo "<div id='content'>          
       	   <div id='content-detail'>";
  	echo "<span class=judul_head>&#187; <b>Hasil Pencarian</b></span><br />";
  	// menghilangkan spasi di kiri dan kanannya
  	$kata = trim($_POST[searchfield]);
  	$pilihan = $_POST[pilihancari];
  	// pisahkan kata per kalimat lalu hitung jumlah kata
  	$pisah_kata = explode(" ",$kata);
  	$jml_katakan = (integer)count($pisah_kata);
  	$jml_kata = $jml_katakan-1;
	
	//Cari semua
	if($pilihan == "all"){
	  	$cari = "SELECT * FROM users WHERE " ;
		for ($i=0; $i<=$jml_kata; $i++){
		  	$cari .= "username LIKE '%$pisah_kata[$i]%'";
		  	if ($i < $jml_kata ){
				$cari .= " OR ";
		  	}
		}
	  	$cari .= " ORDER BY username DESC";
	  	$hasil  = mysql_query($cari);
	  	$ketemu = mysql_num_rows($hasil);
	  	if($ketemu > 0){
	  		echo "<p>Ditemukan <b>$ketemu</b> user dengan username : <font style='background-color:#00FFFF'><b>$kata</b></font> </p>";
	  		$no=0;
			while($t = mysql_fetch_array($hasil)){
				$no++;
				echo "$no. <span class=judul><a href=media.php?module=profilcariuser&username=$t[username]>$t[username]</a></span><br>";
				echo "<img src=ImgAvatar/$t[avatar] width=50 height=50><br>";
			}
		}
	  	else{
	  		echo "<p>Tidak ditemukan user dengan username : <font style='background-color:#00FFFF'><b>$kata</b></font> </p>";
	  	}
	  	$cari = "SELECT Tabel1.* 
FROM (SELECT tag.nama_tag, berita.* FROM berita, tag WHERE tag.id_tag = berita.id_tag) AS Tabel1 WHERE " ;
		for ($i=0; $i<=$jml_kata; $i++){
		  	$cari .= "Tabel1.nama_tag LIKE '%$pisah_kata[$i]%' OR Tabel1.isi_berita LIKE '%$pisah_kata[$i]%'";
		  	if ($i < $jml_kata ){
				$cari .= " OR ";
		  	}
		}
	  	$hasil  = mysql_query($cari);
	  	$ketemu = mysql_num_rows($hasil);
	    if ($ketemu > 0){
			echo "<p>Ditemukan <b>$ketemu</b> berita atau tag dengan kata <font style='background-color:#00FFFF'><b>$kata</b></font> : </p>"; 
			while($t=mysql_fetch_array($hasil)){
				$like = mysql_query("SELECT COUNT(likes.id_berita) AS jml, berita.* FROM likes, berita WHERE likes.id_berita=berita.id_berita AND berita.id_berita=$t[id_berita] GROUP BY likes.id_berita ORDER BY jml DESC");
				$s = mysql_fetch_array($like);
				echo "<table><tr><td><span class=judul><a href=berita-$t[id_berita]-$t[judul_seo].html>$t[judul]</a></span><br />";
				echo "<tr><td><b>Tag : $t[nama_tag]</b><br />";
				if($s[jml]==""){
					echo "<tr><td><b>Like : 0</b><br>";
				}
				else{
					echo "<tr><td><b>Like : $s[jml]</b><br>";
				}
			 	// Tampilkan hanya sebagian isi berita
			  	$isi_berita = htmlentities(strip_tags($t[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
			  	$isi = substr($isi_berita,0,250); // ambil sebanyak 150 karakter
			  	$isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
			  	
				echo "$isi ... <a href=berita-$t[id_berita]-$t[judul_seo].html>Selengkapnya</a>
					<br /></td></tr>
					</table><hr color=#CCC noshade=noshade />";
			}
		}
		else{
			echo "Tidak ditemukan berita atau tag dengan kata <b>$kata</b>";
		}
	}
	
	//Cari username saja
	if($pilihan == "username"){
		$cari = "SELECT * FROM users WHERE " ;
		for ($i=0; $i<=$jml_kata; $i++){
		  	$cari .= "username LIKE '%$pisah_kata[$i]%'";
		  	if ($i < $jml_kata ){
				$cari .= " OR ";
		  	}
		}
	  	$cari .= " ORDER BY username DESC";
	  	$hasil  = mysql_query($cari);
	  	$ketemu = mysql_num_rows($hasil);
	  	if($ketemu > 0){
	  		echo "<p>Ditemukan <b>$ketemu</b> user dengan username : <font style='background-color:#00FFFF'><b>$kata</b></font> </p>";
	  		$no=0;
			while($t = mysql_fetch_array($hasil)){
				$no++;
				echo "$no. <span class=judul><a href=media.php?module=profilcariuser&username=$t[username]>$t[username]</a></span><br>";
				echo "<img src=ImgAvatar/$t[avatar] width=50 height=50><br>";
			}
		}
	  	else{
	  		echo "<p>Tidak ditemukan user dengan username : <font style='background-color:#00FFFF'><b>$kata</b></font> </p>";
	  	}
	}
	
	//Cari konten saja
	if($pilihan == "konten"){
	  	$cari = "SELECT Tabel1.* 
FROM (SELECT tag.nama_tag, berita.* FROM berita, tag WHERE tag.id_tag = berita.id_tag) AS Tabel1 WHERE " ;
		for ($i=0; $i<=$jml_kata; $i++){
		  	$cari .= "Tabel1.nama_tag LIKE '%$pisah_kata[$i]%' OR Tabel1.isi_berita LIKE '%$pisah_kata[$i]%'";
		  	if ($i < $jml_kata ){
				$cari .= " OR ";
		  	}
		}
	  	$hasil  = mysql_query($cari);
	  	$ketemu = mysql_num_rows($hasil);
	    if ($ketemu > 0){
			echo "<p>Ditemukan <b>$ketemu</b> berita atau tag dengan kata <font style='background-color:#00FFFF'><b>$kata</b></font> : </p>"; 
			while($t=mysql_fetch_array($hasil)){
				$like = mysql_query("SELECT COUNT(likes.id_berita) AS jml, berita.* FROM likes, berita WHERE likes.id_berita=berita.id_berita AND berita.id_berita=$t[id_berita] GROUP BY likes.id_berita ORDER BY jml DESC");
				$s = mysql_fetch_array($like);
				echo "<table><tr><td><span class=judul><a href=berita-$t[id_berita]-$t[judul_seo].html>$t[judul]</a></span><br />";
				echo "<tr><td><b>Tag : $t[nama_tag]</b><br />";
				if($s[jml]==""){
					echo "<tr><td><b>Like : 0</b><br>";
				}
				else{
					echo "<tr><td><b>Like : $s[jml]</b><br>";
				}
			 	// Tampilkan hanya sebagian isi berita
			  	$isi_berita = htmlentities(strip_tags($t[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
			  	$isi = substr($isi_berita,0,250); // ambil sebanyak 150 karakter
			  	$isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
			  	
				echo "$isi ... <a href=berita-$t[id_berita]-$t[judul_seo].html>Selengkapnya</a>
					<br /></td></tr>
					</table><hr color=#CCC noshade=noshade />";
			}
		}
		else{
			echo "Tidak ditemukan berita atau tag dengan kata <b>$kata</b>";
		}
	}
	
	//Cari untuk konten + komentar
	if($pilihan == "konten_komentar"){
	  	$highlite = "$pisah_kata[$i]";
		$cari = "SELECT Tabel1.* 
FROM (SELECT tag.nama_tag, berita.* FROM berita, tag WHERE tag.id_tag = berita.id_tag) AS Tabel1 WHERE " ;
		for ($i=0; $i<=$jml_kata; $i++){
		  	$cari .= "Tabel1.nama_tag LIKE '%$pisah_kata[$i]%' OR Tabel1.isi_berita LIKE '%$pisah_kata[$i]%'";
		  	if ($i < $jml_kata ){
				$cari .= " OR ";
		  	}
		}
	  	$hasil  = mysql_query($cari);
	  	$ketemu = mysql_num_rows($hasil);
		//Berita yang dicari ada
	    if ($ketemu > 0){
			echo "<p>Ditemukan <b>$ketemu</b> berita atau komentar dengan kata <font style='background-color:#00FFFF'><b>$kata</b></font> : </p>";
			while($t=mysql_fetch_array($hasil)){
				$caria = "SELECT * FROM komentar WHERE ";
				for ($i=0; $i<=$jml_kata; $i++){
					$caria .= "isi_komentar LIKE '%$pisah_kata[$i]%' AND id_berita = $t[id_berita]";
					if ($i < $jml_kata ){
						$caria .= " OR ";
					}
				}
				$caria .= " ORDER BY id_komentar DESC";
				$hasila  = mysql_query($caria);
				$ketemua = mysql_num_rows($hasila);
				//Tentukan Like
				$like = mysql_query("SELECT COUNT(likes.id_berita) AS jml, berita.* FROM likes, berita WHERE likes.id_berita=berita.id_berita AND berita.id_berita=$t[id_berita] GROUP BY likes.id_berita ORDER BY jml DESC");
				$s = mysql_fetch_array($like);
				
				//Komentar yang dicari ada
				 if ($ketemua > 0){
					echo "<table><tr><td><span class=judul><a href=berita-$t[id_berita]-$t[judul_seo].html>$t[judul]</a></span><br />";
					echo "<tr><td><b>Tag : $t[nama_tag]</b><br />";
					if($s[jml]==""){
						echo "<tr><td><b>Like : 0</b><br>";
					}
					else{
						echo "<tr><td><b>Like : $s[jml]</b><br>";
					}
					// Tampilkan hanya sebagian isi berita
					$isi_berita = htmlentities(strip_tags($t[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
					$isi = substr($isi_berita,0,250); // ambil sebanyak 150 karakter
					$isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
						
					echo "$isi ... <a href=berita-$t[id_berita]-$t[judul_seo].html>Selengkapnya</a>
							<br /></td></tr>";
					while($d=mysql_fetch_array($hasila)){
						echo "<tr><td>Komentar : <br>";
						echo "$d[isi_komentar]</td></tr>";
					}
					echo"</table><hr color=#CCC noshade=noshade />";
				 }
				 else{
					echo "<table><tr><td><span class=judul><a href=berita-$t[id_berita]-$t[judul_seo].html>$t[judul]</a></span><br />";					
					echo "<tr><td><b>Tag : $t[nama_tag]</b><br />";
					if($s[jml]==""){
					echo "<tr><td><b>Like : 0</b><br>";
					}
					else{
						echo "<tr><td><b>Like : $s[jml]</b><br>";
					}
					// Tampilkan hanya sebagian isi berita
					$isi_berita = htmlentities(strip_tags($t[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
					$isi = substr($isi_berita,0,250); // ambil sebanyak 150 karakter
					$isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
					
					echo "$isi ... <a href=berita-$t[id_berita]-$t[judul_seo].html>Selengkapnya</a>
							<br /></td></tr></table><hr color=#CCC noshade=noshade />";
				 }
			}
		}
		else{
			echo "Tidak ditemukan berita atau komentar dengan kata <b>$kata</b>";
		}
	}
	
	//Cari untuk username+info lain
	if($pilihan == "username_infolain"){
		$cari = "SELECT * FROM users WHERE " ;
		for ($i=0; $i<=$jml_kata; $i++){
		  	$cari .= "username LIKE '%$pisah_kata[$i]%' OR email LIKE '%$pisah_kata[$i]%' OR nama_lengkap LIKE '%$pisah_kata[$i]%' OR about LIKE '%$pisah_kata[$i]%'";
		  	if ($i < $jml_kata ){
				$cari .= " OR ";
		  	}
		}
	  	$cari .= " ORDER BY username DESC";
	  	$hasil  = mysql_query($cari);
	  	$ketemu = mysql_num_rows($hasil);
	  	if($ketemu > 0){
			echo "<p>Ditemukan <b>$ketemu</b> user dengan username atau informasi lain : <font style='background-color:#00FFFF'><b>$kata</b></font> </p>";
	  		$no = 0;
			while($t = mysql_fetch_array($hasil)){
				$no++;
				echo "$no. <span class=judul><a href=media.php?module=profilcariuser&username=$t[username]>$t[username]</a></span><br>";
				echo "$t[email]<br>";
				echo "$t[nama_lengkap]<br>";
				echo "$t[about]<br>";
				echo "<img src=ImgAvatar/$t[avatar] width=50 height=50><br>";
			}
	  	}
	  	else{
	  		echo "<p>Tidak ditemukan user dengan username : <font style='background-color:#00FFFF'><b>$kata</b></font> </p>";
	  	}
	}
	
	//Radio button tidak dipilih
	if($pilihan == ""){
		echo "<p><b>Pilih salah satu radio button yang tersedia, tidak boleh kosong!</b></p>";
	}
  echo "</div>
    </div>";            
}
// Modul hasil pencarian sorting
elseif ($_GET[module]=='hasilsorting'){
	echo "<div id='content'>          
       	   <div id='content-detail'>";
	
  	$pilihan = $_POST[pilihancari];
	echo "<span class=judul_head>&#187; <b>Hasil Pencarian</b></span><br />";
		// menghilangkan spasi di kiri dan kanannya
		
	if($pilihan == "most_popular"){
		$cari = "SELECT COUNT(likes.id_berita) AS jml, berita.*,tag.nama_tag FROM likes, berita, tag WHERE likes.id_berita=berita.id_berita AND tag.id_tag=berita.id_tag GROUP BY likes.id_berita ORDER BY jml DESC" ;
		$hasil  = mysql_query($cari);
		$ketemu = mysql_num_rows($hasil);
		if($ketemu > 0){
			echo "<p>Ditemukan <b>$ketemu</b> berita dengan tag : <font style='background-color:#00FFFF'><b>$pilihan</b></font> </p>";
			$no=0;
			while($t = mysql_fetch_array($hasil)){
				echo "<table><tr><td><span class=judul><a href=berita-$t[id_berita]-$t[judul_seo].html>$t[judul]</a></span><br />";
				echo "<b>Tag : $t[nama_tag]</b><br />";
				echo "<b>Pengepost : <span class=judul><a href=media.php?module=profilcariuser&username=$t[username]>$t[username]</a></span></b><br>";
				echo "<b>Like : $t[jml]</b><br>";
				$a = datediff($waktu, $r[waktu]);
				if ($waktu)
				{ echo '<b>Selisih Waktu : </b>'.$a[years].'
				tahun, '.$a[months].'
				bulan, '.$a[days].'
				hari, '.$a[hours].'
				jam, '.$a[minutes].'
				menit, '.$a[seconds].'
				detik';
				}
				echo "<br>";
				// Tampilkan hanya sebagian isi berita
				$isi_berita = htmlentities(strip_tags($t[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
				$isi = substr($isi_berita,0,250); // ambil sebanyak 150 karakter
				$isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
					
				echo "$isi ... <a href=berita-$t[id_berita]-$t[judul_seo].html>Selengkapnya</a>
				<br /></td></tr>
					</table><hr color=#CCC noshade=noshade />";
			}
		}
		else{
			echo "Tidak ditemukan berita dengan tag <b>$pilihan</b>";
		}
	}
	if($pilihan == "most_commented"){
		$cari = "SELECT tag.nama_tag, berita.*, COUNT(komentar.id_komentar) as jml FROM berita, komentar, tag WHERE berita.id_berita = komentar.id_berita AND tag.id_tag=berita.id_tag GROUP BY komentar.id_berita ORDER BY jml DESC" ;
		$hasil  = mysql_query($cari);
		$ketemu = mysql_num_rows($hasil);
		if($ketemu > 0){
			echo "<p>Ditemukan <b>$ketemu</b> berita dengan tag : <font style='background-color:#00FFFF'><b>$pilihan</b></font> </p>";
			$no=0;
			while($t = mysql_fetch_array($hasil)){
				echo "<table><tr><td><span class=judul><a href=berita-$t[id_berita]-$t[judul_seo].html>$t[judul]</a></span><br />";
				echo "<b>Tag : $t[nama_tag]</b><br />";
				echo "<b>Pengepost : <span class=judul><a href=media.php?module=profilcariuser&username=$t[username]>$t[username]</a></span></b><br>";
				$a = datediff($waktu, $r[waktu]);
				if ($waktu)
				{ echo '<b>Selisih Waktu : </b>'.$a[years].'
				tahun, '.$a[months].'
				bulan, '.$a[days].'
				hari, '.$a[hours].'
				jam, '.$a[minutes].'
				menit, '.$a[seconds].'
				detik';
				}
				echo "<br>";
				echo "<b>Jumlah Komentar : $t[jml] </b><br>";
				// Tampilkan hanya sebagian isi berita
				$isi_berita = htmlentities(strip_tags($t[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
				$isi = substr($isi_berita,0,250); // ambil sebanyak 150 karakter
				$isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
					
				echo "$isi ... <a href=berita-$t[id_berita]-$t[judul_seo].html>Selengkapnya</a>
				<br /></td></tr>
					</table><hr color=#CCC noshade=noshade />";
			}
		}
		else{
			echo "Tidak ditemukan berita dengan tag <b>$pilihan</b>";
		}
	}
	if($pilihan == "newest"){
		$cari = "SELECT berita.*, tag.nama_tag FROM berita, tag WHERE berita.id_tag=tag.id_tag ORDER BY waktu DESC" ;
		$hasil  = mysql_query($cari);
		$ketemu = mysql_num_rows($hasil);
		if($ketemu > 0){
			echo "<p>Ditemukan <b>$ketemu</b> berita dengan tag : <font style='background-color:#00FFFF'><b>$pilihan</b></font> </p>";
			$no=0;
			while($t = mysql_fetch_array($hasil)){
				echo "<table><tr><td><span class=judul><a href=berita-$t[id_berita]-$t[judul_seo].html>$t[judul]</a></span><br />";
				echo "<b>Tag : $t[nama_tag]</b><br />";
				echo "<b>Pengepost : <span class=judul><a href=media.php?module=profilcariuser&username=$t[username]>$t[username]</a></span></b><br>";
				$a = datediff($waktu, $r[waktu]);
				if ($waktu)
				{ echo '<b>Selisih Waktu : </b>'.$a[years].'
				tahun, '.$a[months].'
				bulan, '.$a[days].'
				hari, '.$a[hours].'
				jam, '.$a[minutes].'
				menit, '.$a[seconds].'
				detik';
				}
				echo "<br>";
				// Tampilkan hanya sebagian isi berita
				$isi_berita = htmlentities(strip_tags($t[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
				$isi = substr($isi_berita,0,250); // ambil sebanyak 150 karakter
				$isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
					
				echo "$isi ... <a href=berita-$t[id_berita]-$t[judul_seo].html>Selengkapnya</a>
				<br /></td></tr>
					</table><hr color=#CCC noshade=noshade />";
			}
		}
		else{
			echo "Tidak ditemukan berita dengan tag <b>$pilihan</b>";
		}
	}
	  echo "</div>
    </div>";
}


elseif($_GET[module]=='profilcariuser'){
	echo "<div id='content'>          
          <div id='content-detail'>";
$profil = mysql_query("SELECT * FROM users WHERE username='$_GET[username]'");
while($d = mysql_fetch_array($profil)){
	echo "<table align=center>";
    echo "<tr><td colspan=2 align=center><span class=judul>PROFILE</span></td></tr>";
	echo "<tr><td valign=top><b>Nama Lengkap</b>  </td><td> : $d[nama_lengkap] </td></tr>";
	echo "<tr><td valign=top><b>Username</b> </td><td> : $_GET[username] </td></tr>";
	echo "<tr><td valign=top><b>Avatar</b>  </td><td>  <img src=ImgAvatar/$d[avatar] width=100 height=100></td></tr>";
	echo "<tr><td><b>Email</b> </td><td> : $d[email] </td></tr>";
 	echo "<tr><td valign=top><b>Jenis Kelamin</b>  </td><td> : ";
	if($d[kelamin] == 'P'){
		echo "Pria";
	}
	else{
		echo "Wanita";
	} 
	echo"</td></tr>";
	
 	echo "<tr><td><b>About me</b> </td><td> : $d[about] </td></tr>";
	echo "<tr><td><b>Daftar Achievement</b></td><td> : ";
	$achieve = mysql_query("SELECT * FROM achievement WHERE achievement.username ='$_GET[username]'");
	while($s = mysql_fetch_array($achieve)){
		if($s[isi] == 1){
			echo "- Melakukan posting sekali<br>";
		}
		if($s[isi] == 2){
			echo "- Telah melakukan posting 10 kali<br>";
		}
		if($s[isi] == 3){
			echo "- Berkomentar sekali<br>";
		}
		if($s[isi] == 4){
			echo "- Telah berkomentar 20 kali<br>";
		}
		if($s[isi] == 5){
			echo "- Ada setidaknya satu kontennya yang telah pernah di like oleh 100 pengguna lain<br>";
		}
		if($s[isi] == 6){
			echo "- Ada setidaknya satu kontennya yang telah pernah di dislike 100 pengguna lain<br>";
		}
	}
	echo "</td></tr>";
	$komentar = mysql_query("SELECT COUNT(id_komentar) AS jml FROM komentar WHERE komentator='$_GET[username]'");
	$a = mysql_fetch_array($komentar);
	echo "<tr><td><b>Jumlah Komentar</b></td><td> : $a[jml]</td></tr>";
	$berita = mysql_query("SELECT COUNT(id_berita) AS jml FROM berita WHERE username='$_GET[username]'");
	$b = mysql_fetch_array($berita);
	echo "<tr><td><b>Jumlah Konten yang diupload</b></td><td> : $b[jml]</td></tr></table>";
}
  echo "</div>
    </div>";  
}

elseif($_GET[module]=='profiluser'){
echo "<div id='content'>          
          <div id='content-detail'>";

// Check if the user is logged in

if(!isSet($_SESSION['username'])){
	echo "<b>Anda belum Login, silakan <a href='media.php?module=login'>Login</a> terlebih dahulu!<br>Atau jika Anda belum mendaftar, silakan <a href='media.php?module=registrasi'>Registrasi</a> sekarang.</b>";
	//header("Location: media.php?module=login");
	//exit;
}
else{
?>
<HTML>
 <HEAD>
  <TITLE>Private Page</TITLE>
  <META name="Author" Content="Bit Repository">
  <META name="Keywords" Content="private">
  <META name="Description" Content="Private Page">
</HEAD>

 <BODY>
<CENTER>Welcome, <?php echo $_SESSION['username']; ?> | <a href="media.php?module=logout">Logout</a><br /><br />
This is your private page. Here is your profile data.

<?php
$profil = mysql_query("SELECT users.*, achievement.isi FROM users,achievement WHERE users.username='$_SESSION[username]'");
while($d = mysql_fetch_array($profil)){
	echo "<table>";
    echo "<tr><td colspan=2 align=center><span class=judul>PROFILE</span></td></tr>";
	echo "<tr><td valign=top><b>Nama Lengkap</b>  </td><td> : $d[nama_lengkap] </td></tr>";
	echo "<tr><td valign=top><b>Username</b> </td><td> : $_SESSION[username] </td></tr>";
	echo "<tr><td valign=top><b>Avatar</b>  </td><td>  <img src=ImgAvatar/$d[avatar] width=100 height=100></td><td><a href='media.php?module=editprofil_avatar'>Edit</a></td></tr>";
	echo "<tr><td><b>Email</b> </td><td> : $d[email] </td><td><a href=media.php?module=editprofil_email>Edit</a></td></tr>";
 	echo "<tr><td valign=top><b>Jenis Kelamin</b>  </td><td> : ";
	if($d[kelamin] == 'P'){
		echo "Pria";
	}
	else{
		echo "Wanita";
	} 
	echo"</td></tr>";
	
 	echo "<tr><td><b>About me</b> </td><td> : $d[about] </td><td><a href=media.php?module=editprofil_about>Edit</a></td></tr>";
	echo "<tr><td><b>Daftar Achievement</b></td><td> : ";
	if($d[isi] == 1){
		echo "- Melakukan posting sekali<br>";
	}
	if($d[isi] == 2){
		echo "- Telah melakukan posting 10 kali<br>";
	}
	if($d[isi] == 3){
		echo "- Berkomentar sekali<br>";
	}
	if($d[isi] == 4){
		echo "- Telah berkomentar 20 kali<br>";
	}
	if($d[isi] == 5){
		echo "- Ada setidaknya satu kontennya yang telah pernah di like oleh 100 pengguna lain<br>";
	}
	if($d[isi] == 6){
		echo "- Ada setidaknya satu kontennya yang telah pernah di dislike 100 pengguna lain<br>";
	}
	echo "</td></tr>";

	$komentar = mysql_query("SELECT COUNT(id_komentar) AS jml FROM komentar WHERE komentator='$_GET[username]'");
	$a = mysql_fetch_array($komentar);
	echo "<tr><td><b>Jumlah Komentar</b></td><td> : $a[jml]</td></tr>";
	$berita = mysql_query("SELECT COUNT(id_berita) AS jml FROM berita WHERE username='$_GET[username]'");
	$b = mysql_fetch_array($berita);
	echo "<tr><td><b>Jumlah Konten yang diupload</b></td><td> : $b[jml]</td></tr>";

  	$p      = new Paging2;
  	$batas  = 12;
  	$posisi = $p->cariPosisi($batas);
  
  // Tampilkan semua berita
  $sql=mysql_query("SELECT count(komentar.id_komentar) AS jml, judul, judul_seo, 
                       berita.id_berita, gambar, isi_berita
                       FROM berita left join komentar 
                       ON berita.id_berita=komentar.id_berita AND aktif='Y'
					   WHERE username='$_SESSION[username]'
                       GROUP BY berita.waktu DESC LIMIT $posisi,$batas");
  while($r=mysql_fetch_array($sql)){
		$tgl = tgl_indo($r[tanggal]);
		echo "<table><tr><td><br />";
 		echo "<span class=judul><a href=berita-$r[id_berita]-$r[judul_seo].html>$r[judul]</a></span><br />";
      // Tampilkan hanya sebagian isi berita
      $isi_berita = htmlentities(strip_tags($r[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
      $isi = substr($isi_berita,0,220); // ambil sebanyak 150 karakter
      $isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat

      echo "$isi ... <a href=berita-$r[id_berita]-$r[judul_seo].html>Selengkapnya</a> (<b>$r[jml] komentar</b>)
            </td></tr></table>
            <hr color=#CCC noshade=noshade />";
	 }
	
  $jmldata     = mysql_num_rows(mysql_query("SELECT * FROM berita WHERE username = '$_SESSION[username]'"));
  $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
  $linkHalaman = $p->navHalaman($_GET[halprofil], $jmlhalaman);

  echo "Hal: $linkHalaman <br /><br />";

	echo "</table><hr color=#CCC noshade=noshade />";
}
?>
</CENTER>
 </BODY>
</HTML>
<?php
}
  echo "</div>
    </div>";  
}

elseif($_GET[module]==editprofil_avatar){
echo "<div id='content'>
<div id='content-detail'>";
		?>
        <form action="" method="post">
        <tr><td>Gambar</td><td> : <input type="file" name="fupload" id="fupload" size=40> 
               	<br>Tipe gambar harus JPG/JPEG dan ukuran lebar maks: 400 px
                <input name="username" id="username" type="hidden" value="<?php echo "$_SESSION[username]" ?>">
        </td></tr><br>
        <tr><td colspan=2>
			<script type=text/javascript src=ajax_editprofil.js></script>
            <input type=button name=Button value=Save onclick=sendDataAvatar('save_data.php','content'); return false; />
            <input type=reset name=Reset value=Cancel />
        </td></tr>
        </form>
        <?php
		echo "<a href=media.php?module=profiluser>Kembali ke Profil</a>";
echo "</div>
</div>";
}

elseif($_GET[module]==editprofil_email){
echo "<div id='content'>
<div id='content-detail'>";
		?>
        <form action="" method="post">
        <tr><td>Email</td><td> : <input type="text" name="email" id="email" size=40>
                <input name="username" id="username" type="hidden" value="<?php echo "$_SESSION[username]" ?>">
        </td></tr><br>
        <tr><td colspan=2>
			<script type=text/javascript src=ajax_editprofil.js></script>
            <input type=button name=Button value=Save onclick=sendDataEmail('save_data.php','content'); return false; />
            <input type=reset name=Reset value=Cancel />
        </td></tr>
        </form>
        <?php
		echo "<a href=media.php?module=profiluser>Kembali ke Profil</a>";
echo "</div>
</div>";
}

elseif($_GET[module]==editprofil_about){
echo "<div id='content'>
<div id='content-detail'>";
		?>
        <form action="" method="post">
        <tr><td>About</td><td> : <textarea name="about" id="about" cols="50" rows="5"></textarea>
                <input name="username" id="username" type="hidden" value="<?php echo "$_SESSION[username]" ?>">
        </td></tr><br>
        <tr><td colspan=2>
			<script type=text/javascript src=ajax_editprofil.js></script>
            <input type=button name=Button value=Save onclick=sendDataAbout('save_data.php','content'); return false; />
            <input type=reset name=Reset value=Cancel />
        </td></tr>
        </form>
        <?php
		echo "<a href=media.php?module=profiluser>Kembali ke Profil</a>";
echo "</div>
</div>";
}


elseif($_GET[module]==logout){
	mysql_query("UPDATE menu SET aktif = '1' WHERE judul = 'Logout'");
	mysql_query("UPDATE menu SET aktif = '1' WHERE judul = 'Profil User'");
	mysql_query("UPDATE menu SET aktif = '0' WHERE judul = 'Login'");
	mysql_query("UPDATE menu SET aktif = '0' WHERE judul = 'Registrasi'");
	mysql_query("UPDATE menu SET aktif = '1' WHERE judul = 'Halaman Post'");
	
	if(isSet($_SESSION['username']))
	{
	unset($_SESSION['username']);
	if(isSet($_COOKIE[$cookie_name]))
	{
	// remove 'site_auth' cookie
	setcookie ($cookie_name, '', time() - $cookie_time);
	}
	
	header("Location: index.php");
	exit;
	}
}

elseif($_GET[module]==registrasi){
	echo "<div id='content'>          
          <div id='content-detail'>";
		   echo "<h2>Registrasi</h2>
          <form method=POST action='' enctype='multipart/form-data'>
          <table>
		  <tr><td>Username</td><td> : <input type=text name='first_name' if size=20></td></tr>
		  <tr><td>Password</td><td> : <input type=password name='password' size=20></td></tr>
		  <tr><td>Confirm password</td><td> : <input type=password name='confirm_password' size=20></td></tr>
		  <tr><td>Nama Lengkap</td><td> : <input type=text name='nama_lengkap' size=20></td></tr>
		  <tr><td>Tanggal lahir</td><td> : <input type=text name='tanggal_lahir' size=20></td></tr>
          <tr><td>Gambar</td><td> : <input type=file name='fupload' size=40> 
                                          <br>Tipe gambar harus JPG/JPEG dan ukuran lebar maks: 400 px</td></tr>
		  <tr><td>Email</td><td> : <input type=text name='email'></td></tr>
		  <tr><td>Gender</td><td> : <input type=radio name='gender' value='P' checked>Pria
		  							<input type=radio name='gender' value='W'>Wanita </td></tr>
		  <tr><td>About Me</td><td> : <input type=text name='about' style='width: 200px; height: 100px;'></textarea></td></tr>
          <tr><td colspan=2><script type=text/javascript src=ajax.js></script>
        <input type=button name=Button value=Save onclick=sendData('save_data.php','content'); return false; />
        <input type=reset name=Reset value=Cancel /></td></tr>
          </table></form>";
	echo "</div>
    </div>";
}

elseif($_GET[module]==registrasisimpan){
 echo "<div id='content'>          
          <div id='content-detail'>";
		  
	echo "</div>";
	echo "</div>";
}

// Modul hasil poling
elseif ($_GET[module]=='hasilpoling'){
 echo "<div id='content'>          
          <div id='content-detail'>";
 if (isset($_COOKIE["poling"])) {
   echo "Sorry, anda sudah pernah melakukan voting terhadap poling ini.";
 }
 else{
  // membuat cookie dengan nama poling
  // cookie akan secara otomatis terhapus dalam waktu 24 jam
  setcookie("poling", "sudah poling", time() + 3600 * 24);

  echo "<span class=judul_head>&#187; <b>Hasil Poling</b></span><br /><br />";

  $u=mysql_query("UPDATE poling SET rating=rating+1 WHERE id_poling='$_POST[pilihan]'");

  echo "<p align=center>Terimakasih atas partisipasi Anda mengikuti poling kami<br /><br />
        Hasil poling saat ini: </p><br />";
  
  echo "<table width=100% style='border: 1pt dashed #0000CC;padding: 10px;'>";

  $jml=mysql_query("SELECT SUM(rating) as jml_vote FROM poling WHERE aktif='Y'");
  $j=mysql_fetch_array($jml);
  
  $jml_vote=$j[jml_vote];
  
  $sql=mysql_query("SELECT * FROM poling WHERE aktif='Y'");
  
  while ($s=mysql_fetch_array($sql)){
  	
  	$prosentase = sprintf("%2.1f",(($s[rating]/$jml_vote)*100));
  	$gbr_vote   = $prosentase * 3;

    echo "<tr><td width=120>$s[pilihan] ($s[rating]) </td><td> 
          <img src=images/blue.png width=$gbr_vote height=18 border=0> $prosentase % 
          </td></tr>";  
  }
  echo "</table>
        <p>Jumlah Voting: <b>$jml_vote</b></p>";
 }
  echo "</div>
    </div>";            
}

// Modul hasil poling
elseif ($_GET[module]=='lihatpoling'){
  echo "<div id='content'>          
          <div id='content-detail'>";
  echo "<span class=judul_head>&#187; <b>Hasil Poling</b></span><br /><br />";

  echo "<p align=center>Terimakasih atas partisipasi Anda mengikuti poling kami<br /><br />
        Hasil poling saat ini: </p><br />";
  
  echo "<table width=100% style='border: 1pt dashed #0000CC;padding: 10px;'>";

  $jml=mysql_query("SELECT SUM(rating) as jml_vote FROM poling WHERE aktif='Y'");
  $j=mysql_fetch_array($jml);
  
  $jml_vote=$j[jml_vote];
  
  $sql=mysql_query("SELECT * FROM poling WHERE aktif='Y'");
  
  while ($s=mysql_fetch_array($sql)){
  	
  	$prosentase = sprintf("%2.1f",(($s[rating]/$jml_vote)*100));
  	$gbr_vote   = $prosentase * 3;

    echo "<tr><td width=120>$s[pilihan] ($s[rating]) </td><td> 
          <img src=images/blue.png width=$gbr_vote height=18 border=0> $prosentase % 
          </td></tr>";  
  }
  echo "</table>
        <p>Jumlah Voting: <b>$jml_vote</b></p>";
  echo "</div>
    </div>";            
}

// Menu utama di header

// Modul profil
elseif ($_GET[module]=='profilkami'){
  echo "<div id='content'>          
          <div id='content-detail'>";
  echo "<span class=judul_head>&#187; <b>Profil</b></span><br /><br />"; 

	$profil = mysql_query("SELECT * FROM modul WHERE id_modul='37'");
	$r      = mysql_fetch_array($profil);

  echo "<tr><td class=isi>";
  if ($r[gambar]!=''){
		echo "<span class=image><img src='foto_banner/$r[gambar]'></span>";
	}
	$isi_profil=nl2br($r[static_content]);
  echo "$isi_profil";  
  echo "</div>
    </div>";            
}

// Modul tentang kami
elseif ($_GET[module]=='tentangkami'){
  echo "<div id='content'>          
          <div id='content-detail'>";
  echo "<span class=judul_head>&#187; <b>Tentang Kami</b></span><br /><br />"; 

	$tentang = mysql_query("SELECT * FROM modul WHERE id_modul='37'");
	$r      = mysql_fetch_array($tentang);

  echo "<tr><td class=isi>";
  if ($r[gambar]!=''){
		echo "<span class=image><img src='foto_banner/$r[gambar]'></span>";
	}
	$isi_tentang=nl2br($r[static_content]);
  echo "$isi_tentang";  
  echo "</div>
    </div>";            
}

// Modul visi misi
elseif ($_GET[module]=='visimisi'){
  echo "<div id='content'>          
          <div id='content-detail'>";
  echo "<span class=judul_head>&#187; <b>Visi Misi</b></span><br /><br />"; 

	$visimisi = mysql_query("SELECT * FROM modul WHERE id_modul='37'");
	$r      = mysql_fetch_array($visimisi);

  echo "<tr><td class=isi>";
  if ($r[gambar]!=''){
		echo "<span class=image><img src='foto_banner/$r[gambar]'></span>";
	}
	$isi_visimisi=nl2br($r[static_content]);
  echo "$isi_visimisi";  
  echo "</div>
    </div>";            
}

elseif($_GET[module]=='semuaberita_list'){
echo "<div id='content'>
          <div id='content-detail'>";
	$kata = trim($_POST[tagfield]);
	if (!empty($_POST[tag_seo])){
    	$tag_seo = $_POST[tag_seo];
    	$tag=implode(',',$tag_seo);
  	}
  	// pisahkan kata untuk teks
	$pisah_kata = explode(",",$kata);
  	$jml_katakan = (integer)count($pisah_kata);
  	$jml_kata = $jml_katakan-1;
	
	// pisahkan kata untuk list
  	$pisah_kata_list = explode(",",$tag);
  	$jml_katakan_list = (integer)count($pisah_kata_list);
  	$jml_kata_list = $jml_katakan_list-1;
	
		//Form filter tag
		echo "<form method='post' action='media.php?module=semuaberita_list'>";
		$tag = mysql_query('SELECT * FROM tag ORDER BY tag_seo');
				echo"<tr><td>Tag (Label)</td><td>";
				while ($t=mysql_fetch_array($tag)){
					echo "<input type=checkbox value='$t[tag_seo]' name=tag_seo[]>$t[nama_tag]";
				}
		echo "<input type='submit' value='Cari tag' />
		</form>
		<!--Form filter tag dengan input teks-->
		<form method='post' action='media.php?module=semuaberita_teks'> <!-- form pencarian -->";
	?>
			<input type="text" name="tagfield" maxlength="50" value="Pencarian..." onBlur="if(this.value=='') this.value='Pencarian...';" onFocus="if(this.value=='Pencarian...') this.value='';"/>
			<input type="submit" value="Cari tag" />
		</form>
	<?php
		
		$cari = "SELECT Tabel1.* FROM
				(SELECT berita.*, tag.nama_tag FROM berita, tag WHERE  tag.id_tag=berita.id_tag) AS Tabel1 WHERE ";
	
		for ($i=0; $i<=$jml_kata_list; $i++){
		  	$cari .= "Tabel1.nama_tag LIKE '%$pisah_kata_list[$i]%'";
		  	if ($i < $jml_kata_list ){
				$cari .= " OR ";
		  	}
		}
	  	$cari .= " ORDER BY Tabel1.id_berita DESC";
	  	$hasil  = mysql_query($cari);
	  	$ketemu = mysql_num_rows($hasil);
	    if ($ketemu > 0){
			echo "<p>Ditemukan <b>$ketemu</b> berita dengan tag"; 
				for ($i=0; $i<=$jml_kata_list; $i++){
					echo " <font style='background-color:#00FFFF'><b>$pisah_kata_list[$i]</b></font>";
				}
			while($t=mysql_fetch_array($hasil)){
				$like = mysql_query("SELECT COUNT(likes.id_berita) AS jml, berita.* FROM likes, berita WHERE likes.id_berita=berita.id_berita AND berita.id_berita=$t[id_berita] GROUP BY likes.id_berita ORDER BY jml DESC");
				$s = mysql_fetch_array($like);
				echo "<table><tr><td><span class=judul><a href=berita-$t[id_berita]-$t[judul_seo].html>$t[judul]</a></span><br />";
				echo "<tr><td><b>Tag : $t[nama_tag]</b><br />";
				if($s[jml]==""){
					echo "<tr><td><b>Like : 0</b><br>";
				}
				else{
					echo "<tr><td><b>Like : $s[jml]</b><br>";
				}
				// Tampilkan hanya sebagian isi berita
			  	$isi_berita = htmlentities(strip_tags($t[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
			  	$isi = substr($isi_berita,0,250); // ambil sebanyak 150 karakter
			  	$isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
			  	
				echo "$isi ... <a href=berita-$t[id_berita]-$t[judul_seo].html>Selengkapnya</a>
					<br /></td></tr>
					</table><hr color=#CCC noshade=noshade />";
			}
		}
		else{
			echo "Tidak ditemukan berita dengan tag <b>$kata</b>";
		}
echo "</div>
</div>";            
}		  

// Modul semua berita teks
elseif ($_GET[module]=='semuaberita_teks'){
  echo "<div id='content'>
          <div id='content-detail'>";
	
	$kata = trim($_POST[tagfield]);
	if (!empty($_POST[tag_seo])){
    	$tag_seo = $_POST[tag_seo];
    	$tag=implode(',',$tag_seo);
  	}
  	// pisahkan kata untuk teks
	$pisah_kata = explode(",",$kata);
  	$jml_katakan = (integer)count($pisah_kata);
  	$jml_kata = $jml_katakan-1;
	
	// pisahkan kata untuk list
  	$pisah_kata_list = explode(",",$tag);
  	$jml_katakan_list = (integer)count($pisah_kata_list);
  	$jml_kata_list = $jml_katakan_list-1;
	
		//Form filter tag
		echo "<form method='post' action='media.php?module=semuaberita_list'>";
		$tag = mysql_query('SELECT * FROM tag ORDER BY tag_seo');
				echo"<tr><td>Tag (Label)</td><td>";
				while ($t=mysql_fetch_array($tag)){
					echo "<input type=checkbox value='$t[tag_seo]' name=tag_seo[]>$t[nama_tag]";
				}
		echo "<input type='submit' value='Cari tag' />
		</form>
		<!--Form filter tag dengan input teks-->
		</form>
		<!--Form filter tag dengan input teks-->
		<form method='post' action='media.php?module=semuaberita_teks'> <!-- form pencarian -->";
	?>
			<input type="text" name="tagfield" maxlength="50" value="Pencarian..." onBlur="if(this.value=='') this.value='Pencarian...';" onFocus="if(this.value=='Pencarian...') this.value='';"/>
			<input type="submit" value="Cari tag" />
		</form>
	<?php
		
		
		if($kata != "Pencarian..."){
			$cari = "SELECT Tabel1.* FROM
				(SELECT berita.*, tag.nama_tag FROM berita, tag WHERE  tag.id_tag=berita.id_tag) AS Tabel1 WHERE ";
			for ($i=0; $i<=$jml_kata; $i++){
				if(! empty($pisah_kata[$i])){
				$cari .= "Tabel1.nama_tag LIKE '%$pisah_kata[$i]%'";
					if ($i < $jml_kata ){
						if(! empty($pisah_kata[$i+1])){
							$cari .= " OR ";
						}
					}
				}
			}
			$cari .= " ORDER BY Tabel1.id_berita DESC";
		}
		elseif($kata == "Pencarian..."){
			$cari = "SELECT Tabel1.* FROM
			(SELECT berita.*, tag.nama_tag FROM berita, tag WHERE  tag.id_tag=berita.id_tag) AS Tabel1 ORDER BY Tabel1.id_berita DESC";
		}	   
	  	$hasil  = mysql_query($cari);
	  	$ketemu = mysql_num_rows($hasil);
	    if ($ketemu > 0){
			echo "<p>Ditemukan <b>$ketemu</b> berita dengan tag";
				for ($i=0; $i<=$jml_kata; $i++){
					echo " <font style='background-color:#00FFFF'><b>$pisah_kata[$i]</b></font>";
				}
			while($t=mysql_fetch_array($hasil)){
				$like = mysql_query("SELECT COUNT(likes.id_berita) AS jml, berita.* FROM likes, berita WHERE likes.id_berita=berita.id_berita AND berita.id_berita=$t[id_berita] GROUP BY likes.id_berita ORDER BY jml DESC");
				$s = mysql_fetch_array($like);
				echo "<table><tr><td><span class=judul><a href=berita-$t[id_berita]-$t[judul_seo].html>$t[judul]</a></span><br />";
				echo "<tr><td><b>Tag : $t[nama_tag]</b><br />";
				if($s[jml]==""){
					echo "<tr><td><b>Like : 0</b><br>";
				}
				else{
					echo "<tr><td><b>Like : $s[jml]</b><br>";
				}
				// Tampilkan hanya sebagian isi berita
			  	$isi_berita = htmlentities(strip_tags($t[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
			  	$isi = substr($isi_berita,0,250); // ambil sebanyak 150 karakter
			  	$isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
			  	
				echo "$isi ... <a href=berita-$t[id_berita]-$t[judul_seo].html>Selengkapnya</a>
					<br /></td></tr>
					</table><hr color=#CCC noshade=noshade />";
			}
		}
		else{
			echo "Tidak ditemukan berita dengan tag <b>$kata</b>";
		}
echo "</div>
</div>";            
}	

	//Konten klik pertama kali
elseif ($_GET[module]=='semuaberita_default'){
  echo "<div id='content'>
          <div id='content-detail'>";
	
	$kata = trim($_POST[tagfield]);
	if (!empty($_POST[tag_seo])){
    	$tag_seo = $_POST[tag_seo];
    	$tag=implode(',',$tag_seo);
  	}
  	// pisahkan kata untuk teks
	$pisah_kata = explode(",",$kata);
  	$jml_katakan = (integer)count($pisah_kata);
  	$jml_kata = $jml_katakan-1;
	
	// pisahkan kata untuk list
  	$pisah_kata_list = explode(",",$tag);
  	$jml_katakan_list = (integer)count($pisah_kata_list);
  	$jml_kata_list = $jml_katakan_list-1;

	//Form filter tag
	
	echo "<form method='post' action='media.php?module=semuaberita_list'>";
	$tag = mysql_query('SELECT * FROM tag ORDER BY tag_seo');
    		echo"<tr><td>Tag (Label)</td><td>";
    		while ($t=mysql_fetch_array($tag)){
      			echo "<input type=checkbox value='$t[tag_seo]' name=tag_seo[]>$t[nama_tag]";
    		}
    echo "<input type='submit' value='Cari tag' />
	</form>
		<!--Form filter tag dengan input teks-->
		<form method='post' action='media.php?module=semuaberita_teks'> <!-- form pencarian -->";
	?>
			<input type="text" name="tagfield" maxlength="50" value="Pencarian..." onBlur="if(this.value=='') this.value='Pencarian...';" onFocus="if(this.value=='Pencarian...') this.value='';"/>
			<input type="submit" value="Cari tag" />
		</form>
	<?php
  	echo "<span class=judul_head>&#187; <b>Berita</b></span><br /><br />"; 
  	$p      = new Paging8;
  	$batas  = 2;
  	$posisi = $p->cariPosisi($batas);
  	// Tampilkan semua berita
  	$sql=mysql_query("select count(komentar.id_komentar) as jml, judul, judul_seo, 
                       berita.id_berita, gambar, isi_berita, username
                       from berita left join komentar 
                       on berita.id_berita=komentar.id_berita
                       and aktif='Y' 
                       group by berita.id_berita DESC");
  	$no = 0;
    
	while($r=mysql_fetch_array($sql)){
		$no = $no+1;
 		echo "<span class=judul><a href=berita-$r[id_berita]-$r[judul_seo].html>$r[judul]</a></span><br />";
      	echo "Pengepost : <b>$r[username]</b><br>";
		echo "Jumlah Komentar : <b>$r[jml] komentar</b><br>";
		
    // Irvan's scripts
    AddLikeDislike((int)$r[id_berita]);
    
		echo "<table><tr><td>";
		$a = datediff($waktu, $r[waktu]);
		if ($waktu){
			echo 'Selisih Waktu : <b>'.$a[years].'
			tahun, '.$a[months].'
			bulan, '.$a[days].'
			hari, '.$a[hours].'
			jam, '.$a[minutes].'
			menit, '.$a[seconds].'
			detik</b>';
		}
		echo "<br>";
		// Apabila ada gambar dalam berita, tampilkan   
 		if ($r[gambar]!=''){
			echo "<p><span class=image><img src='foto_berita/$r[gambar]' border=0 width=100 heigth=100></span></p>";
		}
		// Apabila ada gambar dalam berita, tampilkan   
 		if ($r[video]!=''){
			echo "<p><span class=image><img src='foto_berita/$r[video]' border=0 width=100 heigth=100></span></p>";
		}
		// Tampilkan hanya sebagian isi berita
      	$isi_berita = htmlentities(strip_tags($r[isi_berita])); // membuat paragraf pada isi berita dan mengabaikan tag html
      	$isi = substr($isi_berita,0,220); // ambil sebanyak 150 karakter
      	$isi = substr($isi_berita,0,strrpos($isi," ")); // potong per spasi kalimat
      	echo "$isi ... <a href=berita-$r[id_berita]-$r[judul_seo].html>Selengkapnya</a>
            </td></tr></table>
            <hr color=#CCC noshade=noshade />";
	}
	$jmldata     = mysql_num_rows(mysql_query("SELECT * FROM berita"));
	$jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
	$linkHalaman = $p->navHalaman($_GET[halberita], $jmlhalaman);

 	echo "Hal: $linkHalaman <br /><br />";
echo "</div>
</div>";            
}


// Modul semua download
elseif ($_GET[module]=='semuadownload'){
  echo "<div id='content'>          
          <div id='content-detail'>";
  echo "<span class=judul_head>&#187; <b>Download</b></span><br /><br />"; 
  $p      = new Paging5;
  $batas  = 20;
  $posisi = $p->cariPosisi($batas);
  // Tampilkan semua download
 	$sql = mysql_query("SELECT * FROM download  
                      ORDER BY id_download DESC LIMIT $posisi,$batas");		 

  echo "<ul>";   
   while($d=mysql_fetch_array($sql)){
      echo "<li><a href='downlot.php?file=$d[nama_file]'>$d[judul]</a> ($d[hits])</li>";
	 }
  echo "</ul><hr color=#CCC noshade=noshade />";
	
  $jmldata     = mysql_num_rows(mysql_query("SELECT * FROM download"));
  $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
  $linkHalaman = $p->navHalaman($_GET[haldownload], $jmlhalaman);

  echo "Hal: $linkHalaman <br /><br />";
  echo "</div>
    </div>";            
}


// Modul semua album
elseif ($_GET[module]=='semuaalbum'){
  echo "<div id='content'>          
          <div id='content-detail'>";
  echo "<span class=judul_head>&#187; <b>Album</b></span><br />"; 
  // Tentukan kolom
  $col = 3;

  $a = mysql_query("SELECT jdl_album, album.id_album, gbr_album, album_seo,  
                  COUNT(gallery.id_gallery) as jumlah 
                  FROM album LEFT JOIN gallery 
                  ON album.id_album=gallery.id_album 
                  WHERE album.aktif='Y'  
                  GROUP BY jdl_album");
  echo "<table><tr>";
  $cnt = 0;
  while ($w = mysql_fetch_array($a)) {
    if ($cnt >= $col) {
      echo "</tr><tr>";
      $cnt = 0;
  }
  $cnt++;


 echo "<td align=center valign=top><br />
    <a href=album-$w[id_album].html>
    <img class='img2' src='img_album/kecil_$w[gbr_album]' border=0 width=120 height=90><br />
    $w[jdl_album]</a><br />($w[jumlah] Foto)<br /></td>";
}
echo "</tr></table>";
  echo "</div>
    </div>";            
}


// Modul galeri foto berdasarkan album
elseif ($_GET[module]=='detailalbum'){
  echo "<div id='content'>          
          <div id='content-detail'>";
  echo "<span class=judul_head>&#187; <a href=semua-album.html><b>Album</b></a> &#187; <b>Galeri Foto</b></span><br />"; 
  $p      = new Paging6;
  $batas  = 3;
  $posisi = $p->cariPosisi($batas);

  // Tentukan kolom
  $col = 5;

  $g = mysql_query("SELECT * FROM gallery WHERE id_album='$_GET[id]' ORDER BY id_gallery DESC LIMIT $posisi,$batas");
  $ada = mysql_num_rows($g);
  
  if ($ada > 0) {
  echo "<table><tr>";
  $cnt = 0;
  while ($w = mysql_fetch_array($g)) {
    if ($cnt >= $col) {
      echo "</tr><tr>";
      $cnt = 0;
    }
    $cnt++;

    echo "<td align=center valign=top><br />
          <a id='galeri' href='img_galeri/$w[gbr_gallery]' title='$w[keterangan]'>
          <img alt='galeri' src='img_galeri/kecil_$w[gbr_gallery]' /></a><br />
          <a href=#><b>$w[jdl_gallery]</b></a></td>";
  }
  echo "</tr></table><br />";

  $jmldata     = mysql_num_rows(mysql_query("SELECT * FROM gallery WHERE id_album='$_GET[id]'"));
  $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
  $linkHalaman = $p->navHalaman($_GET[halgaleri], $jmlhalaman);

  echo "Hal: $linkHalaman <br /><br />";
  }else{
    echo "<p>Belum ada foto.</p>";
  }
  echo "</div>
    </div>";
}


// Modul hubungi kami
elseif ($_GET[module]=='hubungikami'){
  echo "<div id='content'>          
          <div id='content-detail'>";
  echo "<span class=judul_head>&#187; <b>Hubungi Kami</b></span><br /><br />"; 
  echo "<b>Hubungi kami secara online dengan mengisi form dibawah ini:</b>
        <table width=100% style='border: 1pt dashed #0000CC;padding: 10px;'>
        <form action=hubungi-aksi.html method=POST>
        <tr><td>Nama</td><td> : <input type=text name=nama size=40></td></tr>
        <tr><td>Email</td><td> : <input type=text name=email size=40></td></tr>
        <tr><td>Subjek</td><td> : <input type=text name=subjek size=55></td></tr>
        <tr><td valign=top>Pesan</td><td> <textarea name=pesan  style='width: 315px; height: 100px;'></textarea></td></tr>
        <tr><td>&nbsp;</td><td><img src='captcha.php'></td></tr>
        <tr><td>&nbsp;</td><td>(Masukkan 6 kode diatas)<br /><input type=text name=kode size=6 maxlength=6><br /></td></tr>
        </td><td colspan=2><input type=submit name=submit value=Kirim></td></tr>
        </form></table><br />";
  echo "</div>
    </div>";            
}

// Modul hubungi aksi
elseif ($_GET[module]==hubungiaksi){
  echo "<div id='content'>          
          <div id='content-detail'>";

$nama=trim($_POST[nama]);
$email=trim($_POST[email]);
$subjek=trim($_POST[subjek]);
$pesan=trim($_POST[pesan]);

if (empty($nama)){
  echo "Anda belum mengisikan NAMA<br />
  	      <a href=javascript:history.go(-1)><b>Ulangi Lagi</b>";
}
elseif (empty($email)){
  echo "Anda belum mengisikan EMAIL<br />
  	      <a href=javascript:history.go(-1)><b>Ulangi Lagi</b>";
}
elseif (empty($subjek)){
  echo "Anda belum mengisikan SUBJEK<br />
  	      <a href=javascript:history.go(-1)><b>Ulangi Lagi</b>";
}
elseif (empty($pesan)){
  echo "Anda belum mengisikan PESAN<br />
  	      <a href=javascript:history.go(-1)><b>Ulangi Lagi</b>";
}
else{
	if(!empty($_POST['kode'])){
		if($_POST['kode']==$_SESSION['captcha_session']){

  mysql_query("INSERT INTO hubungi(nama,
                                   email,
                                   subjek,
                                   pesan,
                                   tanggal) 
                        VALUES('$_POST[nama]',
                               '$_POST[email]',
                               '$_POST[subjek]',
                               '$_POST[pesan]',
                               '$tgl_sekarang')");
  echo "<span class=posting>&#187; <b>Hubungi Kami</b></span><br /><br />"; 
  echo "<p align=center><b>Terimakasih telah menghubungi kami. <br /> Kami akan segera meresponnya.</b></p>";
		}else{
			echo "Kode yang Anda masukkan tidak cocok<br />
			      <a href=javascript:history.go(-1)><b>Ulangi Lagi</b></a>";
		}
	}else{
		echo "Anda belum memasukkan kode<br />
  	      <a href=javascript:history.go(-1)><b>Ulangi Lagi</b></a>";
	}
}
  echo "</div>
    </div>";
}

elseif($_GET[module]==login){
echo "<div id='content'>          
          <div id='content-detail'>";
require_once 'config.php';

// Is the user already logged in? Redirect him/her to the private page

if(isSet($_SESSION['username']))
{
header("Location: media.php?module=profiluser");
exit;
}
?>
<HTML>
 <HEAD>
  <TITLE>AJAX Login Form</TITLE>

  <META name="Author" Content="Bit Repository">
  <META name="Keywords" Content="ajax, login, form, mootools">
  <META name="Description" Content="A nice & simple AJAX Login Form">

  <script type="text/javascript" src="js/mootools-1.2.1-core-yc.js"></script>
  <script type="text/javascript" src="js/process.js"></script>

  <link rel="stylesheet" type="text/css" href="style/style.css" />
</HEAD>
 <BODY>
<center>
<div id="status">
<fieldset><legend align="center">Authentication</legend>
<div id="login_response"><!-- spanner --></div>
<form id="login" name="login" method="post" action="do_login.php">
<table align="center" width="300" border="0">
<tr>
<td width="80">Username</td><td><input id="name" type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="checkbox" name="autologin" value="1">Remember Me</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input id="submit" type="submit" name="submit" value="Login">
<div id="ajax_loading"><img align="absmiddle" src="images/spinner.gif">&nbsp;Processing...</div></td>
</tr>
</table>
</form>
</fieldset>

</div>
</center>
 </BODY>
</HTML>
<?php
echo "</div>
    </div>";
}

elseif($_GET[module]==halamanpost){
	echo "<div id='content'>          
          <div id='content-detail'>";
		  		  
	echo "</div>
    </div>";
}	

/*
elseif($_GET[module]=='tambahberita'){
echo "<div id='content'>          
          <div id='content-detail'>";
function GetCheckboxes($table, $key, $Label, $Nilai='') {
  $s = "select * from $table order by nama_tag";
  $r = mysql_query($s);
  $_arrNilai = explode(',', $Nilai);
  $str = '';
  while ($w = mysql_fetch_array($r)) {
    $_ck = (array_search($w[$key], $_arrNilai) === false)? '' : 'checked';
    $str .= "<input type=checkbox name='".$key."[]' value='$w[$key]' $_ck>$w[$Label] ";
  }
  return $str;
}

$aksi="media.php?module=simpanberita";
switch($_GET[act]){
  // Tampil Berita
  default:
    echo "<h2>Berita</h2>
          <input type=button value='Tambah Berita' onclick=\"window.location.href='media.php?module=tambahberita';\">
          <table>
          <tr><th>no</th><th>judul</th><th>tgl. posting</th><th>aksi</th></tr>";

    $p      = new Paging;
    $batas  = 10;
    $posisi = $p->cariPosisi($batas);

    $tampil = mysql_query("SELECT * FROM berita ORDER BY id_berita DESC LIMIT $posisi,$batas");  
    $no = $posisi+1;
    while($r=mysql_fetch_array($tampil)){
      $tgl_posting=tgl_indo($r[tanggal]);
      echo "<tr><td>$no</td>
                <td>$r[judul]</td>
                <td>$tgl_posting</td>
		            <td><a href=?module=berita&act=editberita&id=$r[id_berita]>Edit</a> | 
		                <a href='$aksi?module=berita&act=hapus&id=$r[id_berita]&namafile=$r[gambar]'>Hapus</a></td>
		        </tr>";
      $no++;
    }
    echo "</table>";

      $jmldata = mysql_num_rows(mysql_query("SELECT * FROM berita"));
     
    $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
    $linkHalaman = $p->navHalaman($_GET[halaman], $jmlhalaman);

    echo "<div id=paging>Hal: $linkHalaman</div><br>";
 
    break;
  
  case "tambahberita":
    echo "<h2>Tambah Berita</h2>
          <form method=POST action='$aksi?module=berita&act=input' enctype='multipart/form-data'>
          <table>
          <tr><td width=70>Judul</td> <td> : <input type=text name='judul' size=60></td></tr>
          <tr><td>Kategori</td>  <td> : 
          <select name='kategori'>
            <option value=0 selected>- Pilih Kategori -</option>";
            $tampil=mysql_query("SELECT * FROM kategori ORDER BY nama_kategori");
            while($r=mysql_fetch_array($tampil)){
              echo "<option value=$r[id_kategori]>$r[nama_kategori]</option>";
            }
    echo "</select></td></tr>
           <tr><td>Headline</td>    <td> : <input type=radio name='headline' value='Y' checked>Y  
                                         <input type=radio name='publish' value='N'> N</td></tr>
          <tr><td>Isi Berita</td>  <td> <textarea name='isi_berita'  style='width: 600px; height: 350px;'></textarea></td></tr>
          <tr><td>Gambar</td>      <td> : <input type=file name='fupload' size=40> 
                                          <br>Tipe gambar harus JPG/JPEG dan ukuran lebar maks: 400 px</td></tr>";

    $tag = mysql_query("SELECT * FROM tag ORDER BY tag_seo");
    echo "<tr><td>Tag (Label)</td><td> ";
    while ($t=mysql_fetch_array($tag)){
      echo "<input type=checkbox value='$t[tag_seo]' name=tag_seo[]>$t[nama_tag] ";
    }
    
    echo "</td></tr>
          <tr><td colspan=2><input type=submit value=Simpan>
                            <input type=button value=Batal onclick=self.history.back()></td></tr>
          </table></form>";
     break;
    
  case "editberita":
    $edit = mysql_query("SELECT * FROM berita WHERE id_berita='$_GET[id]'");
    $r    = mysql_fetch_array($edit);

    echo "<h2>Edit Berita</h2>
          <form method=POST enctype='multipart/form-data' action=$aksi?module=berita&act=update>
          <input type=hidden name=id value=$r[id_berita]>
          <table>
          <tr><td width=70>Judul</td>     <td> : <input type=text name='judul' size=60 value='$r[judul]'></td></tr>
          <tr><td>Kategori</td>  <td> : <select name='kategori'>";
 
          $tampil=mysql_query("SELECT * FROM kategori ORDER BY nama_kategori");
          if ($r[id_kategori]==0){
            echo "<option value=0 selected>- Pilih Kategori -</option>";
          }   

          while($w=mysql_fetch_array($tampil)){
            if ($r[id_kategori]==$w[id_kategori]){
              echo "<option value=$w[id_kategori] selected>$w[nama_kategori]</option>";
            }
            else{
              echo "<option value=$w[id_kategori]>$w[nama_kategori]</option>";
            }
          }
    echo "</select></td></tr>";

   if ($r[headline]=='Y'){
      echo "<tr><td>Headline</td> <td> : <input type=radio name='headline' value='Y' checked>Y  
                                        <input type=radio name='headline' value='N'> N</td></tr>";
    }
    else{
      echo "<tr><td>Headline</td> <td> : <input type=radio name='headline' value='Y'>Y  
                                        <input type=radio name='headline' value='N' checked>N</td></tr>";
    }
 
          echo "<tr><td>Isi Berita</td>   <td> <textarea name='isi_berita' style='width: 600px; height: 350px;'>$r[isi_berita]</textarea></td></tr>
          <tr><td>Gambar</td>       <td> :  ";
          if ($r[gambar]!=''){
              echo "<img src='../foto_berita/small_$r[gambar]'>";  
          }
    echo "</td></tr>
          <tr><td>Ganti Gbr</td>    <td> : <input type=file name='fupload' size=30> *)</td></tr>
          <tr><td colspan=2>*) Apabila gambar tidak diubah, dikosongkan saja.</td></tr>";

    $d = GetCheckboxes('tag', 'tag_seo', 'nama_tag', $r[tag]);

    echo "<tr><td>Tag (Label)</td><td> $d </td></tr>";
 
    echo  "<tr><td colspan=2><input type=submit value=Update>
                            <input type=button value=Batal onclick=self.history.back()></td></tr>
         </table></form>";
    break;  
}

echo "</div>
    </div>";
}*/
?>      
